<?php

namespace App\Listeners;

use App\Enum\LogsEnum;
use App\Events\OrderCreated;
use App\Models\LogsModel;
use Hhxsv5\LaravelS\Swoole\Task\Event;
use Hhxsv5\LaravelS\Swoole\Task\Listener;

class OrderCreatedAsyncNotification extends Listener
{
    /**
     * Create the event listener.
     *
     * @return void
     */
    public function __construct()
    {
        //
    }

    /**
     * Handle the event.
     *
     * @param  OrderCreated  $event
     * @return void
     */
    public function handle(Event $event)
    {

        // 添加订单日志 20230901 by LC
        LogsModel::query()->create([
            'type'      => LogsEnum::LOGS_TYPE_ORDER,
            'ref_id'    => $event->orderInfo->id,
            'ref_no'  => $event->orderInfo->order_no,
            'user_id'   => $event->orderInfo->user_id,
            'user_type' => LogsEnum::LOGS_USER_TYPE_NORMAL,
            'username'  => LogsEnum::LOGS_USER_NAME,
            'content' => '生成订单',
        ]);
//        // 写入用户的短信
//        $phone = VillagerUserModel::query()->where('id',$userId )->value('phone');
//        if( !empty($phone)) {
//
//            $params = ['name' => SmsScheduleEnum::SMS_DEFAULT_USERNAME, 'code' => $orderNo];
//            $data = [
//                'source' => SmsScheduleEnum::SMS_SOURCE_API,
//                'mobile' => $phone,
//                'template_id' => SmsScheduleEnum::TEMPLATE_ID_ORDER_CREATE_USER,
//                'params' => json_encode($params),
//                'status' => SmsScheduleEnum::SMS_STATUS_UNSEND,
//            ];
//            SmsScheduleModel::query()->insert($data);
//        }
    }
}
